package com.ruoyi.project.warehouse.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.warehouse.domain.WareInventoryType;
import com.ruoyi.project.warehouse.service.IWareInventoryTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 物品类别Controller
 *
 * @author you
 * @date 2022-09-03
 */
@RestController
@RequestMapping("/warehouse/WareInventoryType")
public class WareInventoryTypeController extends BaseController
{
    @Autowired
    private IWareInventoryTypeService wareInventoryTypeService;

    /**
     * 查询物品类别列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:WareInventoryType:list')")
    @GetMapping("/list")
    public AjaxResult list(WareInventoryType wareInventoryType)
    {
        List<WareInventoryType> list = wareInventoryTypeService.selectWareInventoryTypeList(wareInventoryType);
        return AjaxResult.success(list);
    }

    /**
     * 导出物品类别列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:WareInventoryType:export')")
    @Log(title = "物品类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WareInventoryType wareInventoryType)
    {
        List<WareInventoryType> list = wareInventoryTypeService.selectWareInventoryTypeList(wareInventoryType);
        ExcelUtil<WareInventoryType> util = new ExcelUtil<WareInventoryType>(WareInventoryType.class);
        util.exportExcel(response, list, "物品类别数据");
    }

    /**
     * 查询1级类别：种类
     */
    @GetMapping("/allKindType")
    public AjaxResult allKindType(){
        return AjaxResult.success(wareInventoryTypeService.allKindType());
    }


    /**
     * 根据父类id查询其下子类别
     */
    @GetMapping("/findByParentId/{parentId}")
    public AjaxResult findByParentId(@PathVariable("parentId") Long parentId){
        return AjaxResult.success(wareInventoryTypeService.findByParentId(parentId));
    }

    /**
     * 获取物品类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:WareInventoryType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wareInventoryTypeService.selectWareInventoryTypeById(id));
    }

    /**
     * 新增物品类别
     */
    @PreAuthorize("@ss.hasPermi('warehouse:WareInventoryType:add')")
    @Log(title = "物品类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WareInventoryType wareInventoryType)
    {
        return toAjax(wareInventoryTypeService.insertWareInventoryType(wareInventoryType));
    }

    /**
     * 修改物品类别
     */
    @PreAuthorize("@ss.hasPermi('warehouse:WareInventoryType:edit')")
    @Log(title = "物品类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WareInventoryType wareInventoryType)
    {
        return toAjax(wareInventoryTypeService.updateWareInventoryType(wareInventoryType));
    }

    /**
     * 删除物品类别
     */
    @PreAuthorize("@ss.hasPermi('warehouse:WareInventoryType:remove')")
    @Log(title = "物品类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wareInventoryTypeService.deleteWareInventoryTypeByIds(ids));
    }
}
